package cn.as132.service.impl;

import cn.as132.mapper.EmpMapper;
import cn.as132.pojo.Emp;
import cn.as132.service.EmpService;
import cn.as132.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    EmpMapper empMapper;

    @Override
    public PageUtil<Emp> findAll(int pageNo) {
        return findEmp(new PageUtil<Emp>(pageNo));
    }

    public PageUtil<Emp> findAll(int pageNo, int size) {
        return findEmp(new PageUtil<Emp>(pageNo, size));
    }

    public PageUtil<Emp> findEmp(PageUtil<Emp> pageUtil) {
        //设置总记录 （总页码就自动计算了）
        pageUtil.setCount(findCount());
        List<Emp> datas = empMapper.findAll((pageUtil.getPageNo() - 1) * pageUtil.getSize(), pageUtil.getSize());
        pageUtil.setDatas(datas);
        return pageUtil;
    }

    /**
     * 查询总记录
     *
     * @return
     */
    @Override
    public int findCount() {
        return empMapper.findCount();
    }
}
